import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:game2048/digital_evolution/login_page.dart';
import 'package:game2048/main.dart';

typedef ButtonClickCallback = void Function(int clickType);

class GameResultPage extends StatelessWidget {
  final bool isSuccess;
  final int? checkPointNum;
  final ButtonClickCallback? onButtonClick;

  /// 1 下一关  2  重新开始
  const GameResultPage({
    Key? key,
    required this.isSuccess,
    this.checkPointNum,
    this.onButtonClick,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      extendBodyBehindAppBar: true,
      appBar: AppBar(
        backgroundColor: Colors.transparent,
        elevation: 0,
        leading: IconButton(
          icon: Icon(Icons.arrow_back),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
      ),
      backgroundColor: Colors.transparent,
      body: Center(
        child: SizedBox(
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height,
          child: Stack(
            alignment: Alignment.center,
            children: [
              Positioned(
                top: 193,
                child: Image.asset(
                  isSuccess ? 'assets/smile.png' : 'assets/cry.png',
                  width: 118,
                  height: 108,
                ),
              ),
              Positioned(
                top: 193 + 108 - 30,
                child: Image.asset(
                  isSuccess
                      ? 'assets/resultSuccess_bg.png'
                      : 'assets/resultFailure_bg.png',
                  width: 280,
                  height: 90,
                ),
              ),
              Positioned(
                top: 193 + 108 - 30 + 72,
                child: Image.asset(
                  isSuccess
                      ? "assets/textSign_success.png"
                      : "assets/textSign_failure.png",
                  width: 245,
                  height: 68,
                ),
              ),
              Positioned(
                top: 193 + 108 - 30 + 50,
                child: Image.asset(
                  isSuccess ? "assets/success.png" : "assets/failure.png",
                  width: 100,
                  height: 55,
                ),
              ),
              Positioned(
                bottom: 60 + 72,
                child: GlobalMethods.buildStartButton(() {
                  if (onButtonClick != null) {
                    if (isSuccess && (checkPointNum ?? 0) < 5) {
                      onButtonClick!(1);
                    } else {
                      onButtonClick!(0);
                    }
                  }
                }, (isSuccess && (checkPointNum ?? 0) < 5) ? "next".tr() : "restart".tr()),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
